package com.southwind.controller;


import com.southwind.common.Cache;
import com.southwind.entity.User;
import com.southwind.mapper.UserMapper;
import com.southwind.vo.LineVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-04-28
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/line")
    @ResponseBody
    public Map<String, List> line(){
        User user = (User) Cache.map.get("user");
        List<LineVO> lineVOS = this.userMapper.lineData(user.getId());
        List<String> dateList = new ArrayList<>();
        List<Integer> timeList = new ArrayList<>();
        for (LineVO lineVO : lineVOS) {
            timeList.add(lineVO.getTime());
            dateList.add(lineVO.getDate());
        }
        Map<String,List> map = new HashMap<>();
        map.put("dateList",dateList);
        map.put("timeList",timeList);
        return map;
    }

}

